<?php
App::uses('AppController', 'Controller');

class PagesController extends AppController {
	var $name = "Pages";// ten cua Controller
    var $helpers = array('Paginator','Html');
    var $components = array('Session');
    var $paginate = array();

	public function beforeFilter() {
		$this -> Auth -> allow();
		parent::getProductCommon();
	}

	public function home() {
		//$this->Session->read('Config.language');
		$this->loadModel('Product');
		$conditions = array("Product.deleted" => 0);
		//$data = $this->Product->find('all', $conditions);
		$this->paginate = array(
                                'limit' => ITEM_PER_PAGE_USER,
                                'order' => array('Product.id' => 'asc'),
                             );
        //$data = $this->Product->find("all",array ('condition'=>$conditions));
        $data = $this->paginate("Product",$conditions);
        $this->set("data",$data);
		$this->set("title_for_user","Trang Chủ");
	}

	public function change_language($language){
		if($language == 'eng'){
			$this->Session->write('Config.language', 'eng');
		} else {
			$this->Session->write('Config.language', 'vni');
		}
		echo "true";
		exit();
	}
	public function detail($id){
		$this->loadModel('Product');
		$conditions = array("Product.deleted" => 0, "Product.id" => $id);
		$data = $this->Product->find("first",array ('condition'=>$conditions));
		 $this->set("data",$data);
		$this->set("title_for_user","Thông tin");
	}
}
